<?php
namespace app\manager\controller;

use app\manager\model\ManagerModel;
use think\Controller;
use think\Db;
use think\Exception;

/**
 * 不需要授权与登录的控制器业务逻辑
 *
 * Class SiteController
 * @package app\manager\controller
 */
class SiteController extends Controller
{
    /**
     * 登录
     *
     * @return mixed|\think\response\Json|\think\response\Redirect
     */
    public function login()
    {
        if (request()->isPost()) {
            $data = $_REQUEST;

            $model = new ManagerModel();
            $res = $model->login($data);
            if (!$res) {
                return json(['code' => 0, 'msg' => '用户名或者密码错误']);
            }

            return redirect('index/index');
        }

        return $this->fetch();
    }

    /**
     * 没有权限的错误提示页
     *
     * @return mixed
     */
    public function no_permission() {
        return $this->fetch();
    }

    /**
     *  退出，并清除session
     */
    public function logout() {
        $model = new ManagerModel();
        $model->logout();
        return redirect('index/login');
    }

    /**
     * 404
     *
     * @return mixed
     */
    public function not_found() {
        return $this->fetch();
    }

    /**
     * ajax请求验证按钮是否有权限显示
     *
     * @return \think\response\Json
     * @throws \Exception
     */
    public function js_permission_check() {
        $route = input('route', '');
        if (empty($route)) {
            return json(['code' => 0, 'msg' => '参数route不能为空']);
        }
        if (is_show($route)) {
            return json(['code' => 1, 'msg' => 'success']);
        }
        return json(['code' => 0, 'msg' => 'failure']);
    }

    public function manager() {
        $m = new ManagerModel();
        $sql = "select basic_tp_manager_test(2)";
        $res = $m->query($sql);
        //var_dump($res);die;

    }

}
